package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ClientResourcePool;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IClientResourcePoolService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("clientResourcePool")
public class ClientResourcePoolController {

    @Autowired
    IClientResourcePoolService clientResourcePoolService;

    @RequestMapping("")
    @RequiresPermissions(value = {"客户资源池首页","clientResourcePool:index"} ,logical = Logical.OR)
    public String index(){

        return "clientResourcePool/list";
    }

    @RequestMapping("list")
    @RequiresPermissions(value = {"客户资源池列表","clientResourcePool:list"} ,logical = Logical.OR)
    @ResponseBody
    public PageResult list(QueryObject qo){
        PageResult result = clientResourcePoolService.query(qo);
        return result;
    }
    @RequestMapping("listData")
    @ResponseBody
    public Object listData(QueryObject qo){

        return clientResourcePoolService.list();
    }

    @RequestMapping("save")
    @RequiresPermissions(value = {"客户资源池保存","clientResourcePool:save"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult save(ClientResourcePool entity){
        JSONResult result = new JSONResult();
        try{
            clientResourcePoolService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @RequiresPermissions(value = {"客户资源池更新","clientResourcePool:update"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult update(ClientResourcePool entity){
        JSONResult result = new JSONResult();
        try{
            clientResourcePoolService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }


    @RequestMapping("delete")
    @RequiresPermissions(value = {"客户资源池删除","clientResourcePool:delete"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            clientResourcePoolService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }
}
